//https://leetcode.cn/problems/que-shi-de-shu-zi-lcof/description/
class Solution {
public:
    int takeAttendance(vector<int>& records) 
    {
        //数组连续特殊处理一下
        if(records.size()-1==records[records.size()-1])
        	return records.size();
		//具有二段性
        int left=0,right=records.size()-1;
        while(left<right)
        {
            int mid = left + (right-left)/2;
            if(records[mid]==mid)
            	left = mid+1;
            else
            	right = mid;
        }
        return records[left]-1;
    }
};
class Solution {
public:
    int findPeakElement(vector<int>& nums) 
    {
        //随便寻找一个峰值即可
		int	left=0,right=nums.size()-1;
        while(left<right)
        {
            int mid = left + (right-left+1)/2;
            if(nums[mid]>=nums[mid-1])
            	left = mid;
            else
            	right = mid-1;
        }
        return left;
    }
};
class Solution {
public:
    int findMin(vector<int>& nums) 
    {
        int left=0,right=nums.size()-1;
		if(nums[left]<nums[right])
        	return nums[left];
        
        while(left<right)
        {
            int mid = left + (right-left)/2;
            if(nums[mid]>=nums[0])
            	left = mid+1;
            else
            	right = mid;
        }
			return nums[left];
        
    }
};
